package com.swgk.core.view.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
import com.swgk.core.R;
import com.swgk.core.recyclerview.secondary.SecondaryEntity;

import java.io.Serializable;

//材料菜单选项
public class MenuEntity<D> extends SecondaryEntity<D> implements Parcelable, Serializable {
    private String appIconUrl = "https://shigongbang.oss-cn-hangzhou.aliyuncs.com/";
    //                               https://shigongbang.oss-cn-hangzhou.aliyuncs.com/
    @SerializedName(value = "id", alternate = {"no", "code","comNo"})
    private String id = "";
    @SerializedName("name")
    private String name;
    @SerializedName(value = "appIcon", alternate = {"icon", "image", "icon_img","appImg","img"})
    private String appIcon;
    //单个文字
    private String iconContent;
    @SerializedName("selected")
    private boolean selected;
    @SerializedName("imageResource")
    private int imageResource = R.drawable.null_img_list;
    private int hostImg;
    @SerializedName("parentId")
    private String parentId;
    @SerializedName("url")
    private String url;//本地图标名称

    private String realname;
    private long parentNo;
    private int lev;

    public long getParentNo() {
        return parentNo;
    }

    public void setParentNo(long parentNo) {
        this.parentNo = parentNo;
    }

    public int getLev() {
        return lev;
    }

    public void setLev(int lev) {
        this.lev = lev;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    private String simpleName; //地区简写

    public String getSimpleName() {
        return simpleName;
    }

    public void setSimpleName(String simpleName) {
        this.simpleName = simpleName;
    }

    private String murl;

    public String getMurl() {
        return murl;
    }

    public void setMurl(String murl) {
        this.murl = murl;
    }

    public String getIconContent() {
        return iconContent;
    }

    public void setIconContent(String iconContent) {
        this.iconContent = iconContent;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getAppIconUrl() {
        return appIconUrl;
    }

    public void setAppIconUrl(String appIconUrl) {
        this.appIconUrl = appIconUrl;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public int getImageResource() {
        return imageResource;
    }

    public void setImageResource(int imageResource) {
        this.imageResource = imageResource;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        if (TextUtils.isEmpty(name)) return "";
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAppIcon() {
        if (appIcon == null) {
            return "";
        } else if (appIcon.contains(appIconUrl)) {
            return appIcon;
        } else {
            return appIconUrl + appIcon;
        }
    }

    public void setAppIcon(String appIcon) {
        this.appIcon = appIcon;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.name);
        dest.writeString(this.appIcon);
    }

    public MenuEntity() {
    }

    public MenuEntity(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public MenuEntity(String id, String iconContent, String name) {
        this.id = id;
        this.iconContent = iconContent;
        this.name = name;
    }

    public MenuEntity(String id, String iconContent, String name, String url) {
        this.id = id;
        this.url = url;
        this.name = name;
    }

    public MenuEntity(String name, String appIcon, int imageResource) {
        this.name = name;
        this.appIcon = appIcon;
        this.imageResource = imageResource;
    }

    protected MenuEntity(Parcel in) {
        this.id = in.readString();
        this.name = in.readString();
        this.appIcon = in.readString();
    }

    public static final Parcelable.Creator<MenuEntity> CREATOR = new Parcelable.Creator<MenuEntity>() {
        @Override
        public MenuEntity createFromParcel(Parcel source) {
            return new MenuEntity(source);
        }

        @Override
        public MenuEntity[] newArray(int size) {
            return new MenuEntity[size];
        }
    };

    public int getHostImg() {
        return hostImg;
    }

    public void setHostImg(int hostImg) {
        this.hostImg = hostImg;
    }
}
